#include <QDebug>
#include "mallet.h"
#include "object_builder.h"

Mallet::Mallet(float radius, float height, int numPoints):
    m_radius(radius), m_height(height), m_numPoints(numPoints) {
    // 两个圆盘，两个圆筒
    int vertexSize = 2 * circleVertexSize(numPoints) + 2 * openCylinderVertexSize(numPoints);
    // 三维坐标
    m_vertexData = new float[vertexSize * 3];
    
    Point3D center(0.f, -height / 2.f, 0.f);
    // 木槌底盘
    float baseHeight = 0.25f * height;
    // 底盘圆筒
    center.translateY(baseHeight/2.f);
    m_baseCylinder = new Cylinder3D(center, radius, baseHeight);
    // 底盘上圆面
    center.translateY(baseHeight/2.f);
    m_baseCircle = new Circle3D(center, radius);
    // 木槌手柄
    float handleHeight = height - baseHeight;
    float handleRadius = radius / 3.f;
    // 手柄圆筒
    center.translateY(handleHeight / 2.f);
    m_handleCylinder = new Cylinder3D(center, handleRadius, handleHeight);
    // 手柄上圆面
    center.translateY(handleHeight / 2.f);
    m_handleCircle = new Circle3D(center, handleRadius);
    // 坐标数据
    int start = appendOpenCylinder(m_vertexData, 0, m_baseCylinder, numPoints);
    start = appendCircle(m_vertexData, start, m_baseCircle, numPoints);
    start = appendOpenCylinder(m_vertexData, start, m_handleCylinder, numPoints);
    appendCircle(m_vertexData, start, m_handleCircle, numPoints);
};
